package com.xixi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xixi.anno.Log;
import com.xixi.pojo.dto.OrderDTO;
import com.xixi.pojo.query.OrderQueryPage;
import com.xixi.pojo.vo.OrderVO;
import com.xixi.pojo.vo.Result;
import com.xixi.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("/page")
    public Result page(OrderQueryPage queryPage){
        IPage<OrderVO> page = orderService.page(queryPage);
        return Result.success(page);
    }
    @GetMapping("/orderById/{id}")
    public Result orderById(@PathVariable Integer id){
        OrderVO orderVO = orderService.orderById(id);
        return Result.success(orderVO);
    }
    @GetMapping("/orderListById/{id}")
    public Result orderListById(@PathVariable Integer id){
        List<OrderVO> orderVO = orderService.orderListById(id);
        return Result.success(orderVO);
    }
    @Log
    @PostMapping("/insert")
    public Result insert(@RequestBody OrderDTO orderDTO){
        return orderService.insert(orderDTO);
    }
    @Log
    @PostMapping("/buy")
    public Result buy(@RequestBody OrderDTO orderDTO){
        return orderService.buy(orderDTO);
    }
    @Log
    @PostMapping("/pay")
    public Result pay(@RequestParam List<Integer> ids){
        return orderService.pay(ids);
    }
    @Log
    @PostMapping("/receive")
    public Result receive(@RequestParam List<Integer> ids){
        return orderService.receive(ids);
    }
    @Log
    @PostMapping("/refund")
    public Result refund(@RequestBody OrderDTO orderDTO){
        return orderService.update(orderDTO);
    }
    @Log
    @PostMapping("/cancel")
    public Result cancel(@RequestBody OrderDTO orderDTO){
        return orderService.update(orderDTO);
    }
    @Log
    @PutMapping("/update")
    public Result update(@RequestBody OrderDTO orderDTO){
        return orderService.update(orderDTO);
    }
    @Log
    @DeleteMapping("/delete")
    public Result delete(@RequestParam List<Integer> ids){
        return orderService.delete(ids);
    }
}
